# Maintainer: Miloš Komarčević <miloskomarcevic@aim.com>

_pyname=lazy_loader
_realname=lazy-loader
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.4
pkgrel=2
pkgdesc="Populate library namespace without incurring immediate import costs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/lazy-loader'
)
url='https://github.com/scientific-python/lazy_loader'
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-cov")
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('47c75182589b91a4e1a85a136c074285a5ad4d9f39c63e0d7fb76391c4574cd1')

build() {
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 README.md "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/README.md"

  local _pyver=$(${MINGW_PREFIX}/bin/python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
  rm -rfv "${pkgdir}${MINGW_PREFIX}/lib/python${_pyver}/site-packages/${_pyname}/tests"
}
